﻿using System;
using Dsl.Ped.Common.Helpers;

namespace Dsl.Ped.Common.Extensions
{
    /// <summary>
    /// Extensions of <see cref="object"/>
    /// </summary>
    public static class ObjectExtension
    {
        /// <summary>
        /// Tries to convert an object into a given <see cref="Type"/>
        /// </summary>
        /// <typeparam name="T">Type to which the conversion should be done</typeparam>
        /// <param name="obj">Object to be converted</param>
        /// <returns>Object converted into the required type, default value if the conversion didn't succeed</returns>
        public static T TryConvert<T>(this object obj)
        {
            return ObjectHelper.TryConvert<T>(obj);
        }

        /// <summary>
        /// Check if the object <see cref="element"/> is in the object graph of <see cref="parent"/> object
        /// </summary>
        /// <param name="parent">Parent object of the object graph</param>
        /// <param name="element">Element we want to check</param>
        /// <returns>True, if <see cref="element"/> is in the object graph of <see cref="parent"/> object, False otherwise</returns>
        public static bool IsInObjectGraph(this object parent, object element)
        {
            return ObjectGraphHelper.IsInObjectGraph(parent, element);
        }
    }
}
